package com.app.miwawa.api.esm.entity.contract;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.framework.common.api.entity.CommonEntityUUID;
import org.framework.common.ext.util.StringUtil;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 购买信息
 * <p>描述: 合同</p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date 2016年1月30日 下午3:54:12
 * @version 1.0.2016
 */
@Entity @Table(name = "TB_ESM_CONTRACT_BUYINFO")
public class Buyinfo extends CommonEntityUUID {

	/** serialVersionUID(long):. */
	private static final long serialVersionUID = -3540884042450864243L;
	


	// 购买类型（托班：全托、半托，早教：亲子课、兴趣课）
	@Column(name = "type", length = 10, nullable = true)
	private String type;
	
	// 购买（月数、课时）
	@Column(name = "buying", length = 10, nullable = true)
	private String buying;
		
	// 赠送（月数、课时）
	@Column(name = "giving", length = 10, nullable = true)
	private String giving;
	
	// 已用（月数、课时）
	@Column(name = "useing", length = 10, nullable = true)
	private String useing;
	
	// 总数（总月数、总课时）
	@Column(name = "totals", length = 10, nullable = true)
	private String totals;
	
	// 单价
	@Column(name = "price_unit", nullable = true)
	private Float priceUnit;
	
	// 总价
	@Column(name = "price_total", nullable = true)
	private Float priceTotal;
	
	// 开始时间
	@Temporal(TemporalType.DATE)
	@JsonFormat(pattern="yyyy-MM-dd", timezone="GMT+8")
	@DateTimeFormat(pattern="yyyy-MM-dd")
	@Column(name = "from_date", nullable = true)
	private Date fromDate;
	
	// 结束时间
	@Temporal(TemporalType.DATE)
	@JsonFormat(pattern="yyyy-MM-dd", timezone="GMT+8")
	@DateTimeFormat(pattern="yyyy-MM-dd")
	@Column(name = "over_date", nullable = true)
	private Date overDate;
	
	// 合同ID
	@Column(name = "contract_id", length = 50, nullable = true)
	private String contractId;

	public Buyinfo() {

	}
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getBuying() {
		return buying;
	}

	public void setBuying(String buying) {
		this.buying = buying;
	}

	public String getGiving() {
		return giving;
	}

	public void setGiving(String giving) {
		this.giving = giving;
	}

	public String getUseing() {
		return useing;
	}

	public void setUseing(String useing) {
		this.useing = useing;
	}
	
	public void setUseing(String item, long count, boolean minus, float usecount)throws NullPointerException{
		if(StringUtil.isNotEmpty(item)){
			switch (item) {
				case "早教":
					this.useing = String.valueOf(minus ? Float.parseFloat(useing) - Float.valueOf(usecount) : Float.parseFloat(useing) + Float.valueOf(usecount));
				break;
				case "托班":
					if(count == 1 || count == 11){
						this.useing = String.valueOf(minus ? Float.parseFloat(useing) - 0.5 : Float.parseFloat(useing) + 0.5);
					}
				break;
			}
		}
	}

	public String getTotals() {
		return totals;
	}

	public void setTotals(String totals) {
		this.totals = totals;
	}

	public Float getPriceUnit() {
		return priceUnit;
	}

	public void setPriceUnit(Float priceUnit) {
		this.priceUnit = priceUnit;
	}

	public Float getPriceTotal() {
		return priceTotal;
	}

	public void setPriceTotal(Float priceTotal) {
		this.priceTotal = priceTotal;
	}

	public Date getFromDate() {
		return fromDate;
	}

	public void setFromDate(Date fromDate) {
		this.fromDate = fromDate;
	}

	public Date getOverDate() {
		return overDate;
	}

	public void setOverDate(Date overDate) {
		this.overDate = overDate;
	}

	public String getContractId() {
		return contractId;
	}

	public void setContractId(String contractId) {
		this.contractId = contractId;
	}
	
}
